package net.models;

// Generated 11 avr. 2013 10:40:17 by Hibernate Tools 3.4.0.CR1

import static javax.persistence.GenerationType.IDENTITY;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;

/**
 * Users generated by hbm2java
 */
@Entity
@Table(name = "users", catalog = "bom", uniqueConstraints = @UniqueConstraint(columnNames = "username"))
public class Users extends AbstractModel {

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Users)
			return ((Users) obj).getId().equals(id);
		return super.equals(obj);
	}

	private Integer					id;
	private Groups					groups;
	private String					name;
	private String					prenom;
	private String					adresse;
	private String					cp;
	private String					ville;
	private Date					dateEmbauche;
	private String					username;
	private String					password;
	private short					admin;
	private Set<RapportsVisites>	rapportsVisites	= new HashSet<RapportsVisites>(0);
	private Set<Fichefrais>			fichefraises	= new HashSet<Fichefrais>(0);

	public Users() {
	}

	public Users(Integer id, Groups groups, String password, String username) {
		this.id = id;
		this.groups = groups;
		this.password = password;
		this.username = username;
	}

	public Users(Integer id, String name, String prenom, String adresse, String cp, String ville, Date dateEmbauche, String username, String password, Groups groups) {
		this.id = id;
		this.name = name;
		this.prenom = prenom;
		this.adresse = adresse;
		this.cp = cp;
		this.ville = ville;
		this.dateEmbauche = dateEmbauche;
		this.username = username;
		this.password = password;
		this.groups = groups;
	}

	public Users(String name, String prenom, String adresse, String cp, String ville, Date dateEmbauche, String username, String password, Groups groups) {
		this.name = name;
		this.prenom = prenom;
		this.adresse = adresse;
		this.cp = cp;
		this.ville = ville;
		this.dateEmbauche = dateEmbauche;
		this.username = username;
		this.password = password;
		this.groups = groups;
	}

	public Users(Groups groups, String username, String password, short admin) {
		this.groups = groups;
		this.username = username;
		this.password = password;
		this.admin = admin;
	}

	public Users(Groups groups, String name, String prenom, String adresse, String cp, String ville, Date dateEmbauche, String username, String password, short admin, Date created, Date modified, Set<RapportsVisites> rapportsVisites, Set<Fichefrais> fichefraises) {
		this.groups = groups;
		this.name = name;
		this.prenom = prenom;
		this.adresse = adresse;
		this.cp = cp;
		this.ville = ville;
		this.dateEmbauche = dateEmbauche;
		this.username = username;
		this.password = password;
		this.admin = admin;
		this.rapportsVisites = rapportsVisites;
		this.fichefraises = fichefraises;
	}

	public Users(String name, String prenom, String adresse, String cp, String ville, String username, String password, Groups groups) {
		this.name = name;
		this.prenom = prenom;
		this.adresse = adresse;
		this.cp = cp;
		this.ville = ville;
		this.username = username;
		this.password = password;
		this.groups = groups;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id", unique = true, nullable = false)
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		Integer oldValue = this.id;
		this.id = id;
		firePropertyChange("id", oldValue, id);
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "group_id", nullable = false)
	public Groups getGroups() {
		return this.groups;
	}

	public void setGroups(Groups groups) {
		Groups oldValue = this.groups;
		this.groups = groups;
		firePropertyChange("groups", oldValue, groups);
	}

	@Column(name = "name", length = 25)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		String oldValue = this.name;
		this.name = name;
		firePropertyChange("name", oldValue, name);
	}

	@Column(name = "prenom", length = 50)
	public String getPrenom() {
		return this.prenom;
	}

	public void setPrenom(String prenom) {
		String oldValue = this.prenom;
		this.prenom = prenom;
		firePropertyChange("prenom", oldValue, prenom);
	}

	@Column(name = "adresse", length = 50)
	public String getAdresse() {
		return this.adresse;
	}

	public void setAdresse(String adresse) {
		String oldValue = this.adresse;
		this.adresse = adresse;
		firePropertyChange("adresse", oldValue, adresse);
	}

	@Column(name = "cp", length = 5)
	public String getCp() {
		return this.cp;
	}

	public void setCp(String cp) {
		String oldValue = this.cp;
		this.cp = cp;
		firePropertyChange("cp", oldValue, cp);
	}

	@Column(name = "ville", length = 30)
	public String getVille() {
		return this.ville;
	}

	public void setVille(String ville) {
		String oldValue = this.ville;
		this.ville = ville;
		firePropertyChange("ville", oldValue, ville);
	}

	@Temporal(TemporalType.DATE)
	@Column(name = "dateEmbauche", length = 10)
	public Date getDateEmbauche() {
		return this.dateEmbauche;
	}

	public void setDateEmbauche(Date dateEmbauche) {
		Date oldValue = this.dateEmbauche;
		this.dateEmbauche = dateEmbauche;
		firePropertyChange("dateEmbauche", oldValue, dateEmbauche);
	}

	@Column(name = "username", unique = true, nullable = false)
	public String getUsername() {
		return this.username;
	}

	public void setUsername(String username) {
		String oldValue = this.username;
		this.username = username;
		firePropertyChange("username", oldValue, username);
	}

	@Column(name = "password", nullable = false, length = 40)
	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		String oldValue = this.password;
		this.password = password;
		firePropertyChange("password", oldValue, password);
	}

	@Column(name = "admin", nullable = false)
	public short getAdmin() {
		return this.admin;
	}

	public void setAdmin(short admin) {
		short oldValue = this.admin;
		this.admin = admin;
		firePropertyChange("admin", oldValue, admin);
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "users")
	public Set<RapportsVisites> getRapportsVisites() {
		return this.rapportsVisites;
	}

	public void setRapportsVisites(Set<RapportsVisites> rapportsVisites) {
		Set<RapportsVisites> oldValue = this.rapportsVisites;
		this.rapportsVisites = rapportsVisites;
		firePropertyChange("rapportsVisites", oldValue, rapportsVisites);
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "users")
	public Set<Fichefrais> getFichefraises() {
		return this.fichefraises;
	}

	public void setFichefraises(Set<Fichefrais> fichefraises) {
		Set<Fichefrais> oldValue = this.fichefraises;
		this.fichefraises = fichefraises;
		firePropertyChange("fichefraises", oldValue, fichefraises);
	}

	public Boolean EstCeQueResponsable() {
		if (this.getGroups().getId().equals(6)) {
			return true;
		} else {
			return false;
		}
	}
}
